package com.beagle.njddapp.weight.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.beagle.njddapp.R;
import com.beagle.njddapp.bean.ZkBean;
import com.beagle.njddapp.bean.oil.OilHomeBean;
import com.beagle.njddapp.bean.owner.NjBean;
import com.beagle.njddapp.bean.owner.OilOrderBean;
import com.beagle.njddapp.core.LocationManager;
import com.beagle.njddapp.core.UserService;
import com.blankj.utilcode.util.ToastUtils;

import java.text.DecimalFormat;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author hxx
 * @date 2021-03-13 20:13
 * 农机主 线上支付
 */
public class NJOilPayDIalog extends Dialog {

    @BindView(R.id.tv_number)
    TextView tvNumber;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_user)
    TextView tvUser;
    @BindView(R.id.tv_chepai)
    TextView tvCp;
    @BindView(R.id.tv_exit)
    TextView tvExit;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_dirver)
    TextView tvdirver;
    @BindView(R.id.ll_zk)
    LinearLayout llZk;
    private NjOilPayCallBack njOilPayCallBack;
    private String realUnit;//打折后的门店价

    public void setNjOilPayCallBack(NjOilPayCallBack njOilPayCallBack) {
        this.njOilPayCallBack = njOilPayCallBack;
    }

    java.text.DecimalFormat decimalFormat =new java.text.DecimalFormat("#.##");
    private OilOrderBean oilOrderBean;


    public NJOilPayDIalog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_nj_oilorder_pay);
        ButterKnife.bind(this);
        if (getWindow() != null) {
            //按空白处不能取消动画
            setCanceledOnTouchOutside(true);
            //设置window背景，默认的背景会有Padding值，不能全屏。当然不一定要是透明，你可以设置其他背景，替换默认的背景即可。
            getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            //一定要在setContentView之后调用，否则无效
            getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            getWindow().setWindowAnimations(R.style.DialogAnim);
        }
    }
    public void update(NjBean njBean, OilOrderBean oilOrderBean, ZkBean zkBean) {
        this.oilOrderBean = oilOrderBean;
        llZk.removeAllViews();
        tvNumber.setText("加油订单"+oilOrderBean.getOrderNum());
        tvPrice.setText("门店价"+decimalFormat.format(Double.parseDouble(zkBean.getOilPrice()))+"元/升");
        tvName.setText(oilOrderBean.getTakerCarNum());
        tvCp.setText(zkBean.getMeter()+"L");
        String price=decimalFormat.format(Double.parseDouble(zkBean.getOilPrice())*Double.parseDouble(zkBean.getMeter()));
        tvdirver.setText(price+"元");
        tvUser.setText(oilOrderBean.getArriveTime());

        if(!TextUtils.isEmpty(zkBean.getDiscountOneName())){
            addZk(zkBean.getDiscountOneName()+"-"+zkBean.getDiscountOneValue()+"%",zkBean.getDiscountOneCut());
        }
        if(!TextUtils.isEmpty(zkBean.getDiscountTwoName())){
            addZk(zkBean.getDiscountTwoName()+"-"+zkBean.getDiscountTwoValue()+"%",zkBean.getDiscountTwoCut());
        }
        realUnit=zkBean.getActualPrice();
        tvExit.setText("线上支付"+realUnit+"元");


    }

    public void addZk(String name,String price){
        View view=getLayoutInflater().inflate(R.layout.item_zk,null);
        TextView tvNmae=view.findViewById(R.id.title_tv);
        TextView tvCount=view.findViewById(R.id.tv_zk);
        tvNmae.setText(name);
        tvCount.setText("-"+decimalFormat.format(Double.parseDouble(price))+"元");
        llZk.addView(view);

    }
    @OnClick({R.id.container, R.id.tv_exit})
    public void onCLick(View view) {
        switch (view.getId()) {
            case R.id.container:
                dismiss();
                break;
            case R.id.tv_exit:
                if (njOilPayCallBack!=null){
                    njOilPayCallBack.choosePay(oilOrderBean,realUnit);
                }
                dismiss();
                break;


        }
    }

    public interface NjOilPayCallBack {
        void choosePay(OilOrderBean oilOrderBean, String price);
    }
}
